package com.itheima.day09_TreeSet.Test3;

import java.util.Comparator;
import java.util.TreeSet;

/*3、【编号：1506】在某次考试中，学生的成绩信息如下：
姓名 年龄 成绩 Tom 20 90 Jerry 22 95 John 20 100 Lily 22 100 Lucy 22 90 Kevin 22 90
请分别用Comparable和Comparator两个接口对以上同学的成绩做降序排序，
如果成绩一样，那在成绩排序的基础上按照年龄由小到大排序，
成绩和年龄都一样，则按照姓名的字典顺序排序。*/
public class Demo3 {
    public static void main(String[] args) {
        TreeSet<Student> set = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //成绩 降序排列
                int res = o2.getCj() - o1.getCj();
                //年龄 升序排列
                res = res == 0 ? o1.getAge() - (o2.getAge()) : res;
                res = res == 0 ? o1.getName().compareTo(o2.getName()) : res;
                return res;
            }
        });
        Student stu1 = new Student("Tom", 20, 90);
        Student stu2 = new Student("Jerry", 22, 95);
        Student stu3 = new Student("John", 20, 100);
        Student stu4 = new Student("Lily", 22, 100);
        Student stu5 = new Student("Lucy", 22, 90);
        Student stu6 = new Student("Kevin", 22, 90);
        Student stu7 = new Student("Kevin", 22, 90);
        set.add(stu1);
        set.add(stu2);
        set.add(stu3);
        set.add(stu4);
        set.add(stu5);
        set.add(stu6);
        set.add(stu7);
        for (Student student : set) {
            System.out.println(student);
        }


    }
}
